﻿function GetFilter2(grd) {
    try {
        grd = eval(grd);
        if (grd == null || grd == undefined)
            return '';
        var datastring = '';
        var values = grd.getStore().getRecordsValues();
        var filter = new Object();
        for (index = 0; index < values.length; index++) {
            if (values[index].FIELD != '' && values[index].VALUE != '') {
                if (values[index].FIELD != undefined && values[index].VALUE != undefined)
                    eval(String.format("filter.{0} = '{1}';", values[index].FIELD, values[index].VALUE));
            }
        }
        return filter;
    }
    catch (err) {
        return '';
    }

    // stoList.autoLoad.params.filter = Ext.encode(filter);
    //stoList.reload();
}

function grdFilterCommand(command, record, rowIndex, colIndex) {
    if (record.store.getTotalCount() <= 1) {
        if (btnAdvSearch != undefined)
            btnAdvSearch.hide();
        if (stoList != undefined && stoList.autoLoad.params != undefined) {
            stoList.autoLoad.params.filter = '';
            stoList.reload();
        }
    }
    if (command == 'DELETESELECTED') {
        record.store.remove(record);
        if (rowIndex <= 0) {
            if (Ext.getCmp('grpAdvanceFilter'))
                Ext.getCmp('grpAdvanceFilter').hide();
        }
        ViewPort1.syncSize();
        btnAdvSearch.fireEvent('Click');
    }

}
function getFilter(grd, filter1) {
    var filter = null;
    if (typeof (filter1) == 'undefined' || filter1 == null)
        filter = new Object();
    else {
        filter = (filter1);
    }
    var columns = grd.columns;
    for (var ix = 0; ix < columns.length; ix++) {
        var field = grd.columns[ix].dataIndex;
        var cotrol = grd.columns[ix].items.items[0].items.items[0];
        if (!Ext.isEmpty(field) && field != 'Selected') {
            if (cotrol != null && !Ext.isEmpty(cotrol.getValue())) {
                if (cotrol.xtype == 'combo' || cotrol.xtype == 'netmulticombo') {
                    if (!Ext.isEmpty(cotrol.getText()))
                        eval(Ext.String.format('filter.{0} = Ext.getCmp("{1}").getValue();', field, cotrolt.id));
                }
                else if (cotrol.xtype == 'datefield') {
                    eval(Ext.String.format('filter.{0} = Ext.getCmp("{1}").getValue().format(dateStandartFormat);', field, cotrol.id));
                }
                else {
                    eval(Ext.String.format('filter.{0} = Ext.getCmp("{1}").getRawValue();', field, cotrol.id));
                }
            }
        }
    }
    return filter;
}
function clearFilter() {
    var columns = this.up('panel').columns;
    for (var ix = 0; ix < columns.length; ix++) {
        var field = this.up('panel').columns[ix].dataIndex;
        var cotrol = this.up('panel').columns[ix].items.items[0].items.items[0];
        if (!Ext.isEmpty(field) && field != 'Selected') {
            if (cotrol != null && !Ext.isEmpty(cotrol.getRawValue()))
                cotrol.reset();
        }
    }
    this.up('panel').store.autoLoad.params.filter = "";
    this.up('panel').store.reload();
}
function applyFilter() {
    if (arguments[0].getValue() == '')
        return;
    var filter = getFilter(this.up('panel'));
    this.up('panel').store.autoLoad.params.filter = Ext.encode(filter);
    this.up('panel').store.reload();
}